// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2023 Yevhen Babiichuk (DustDFG)

#include <DotSort/GameRules/Tube.hpp>

#include <cstdint>
#include <vector>

Tube::Tube(uint8_t size) : size(size)
{
	this->dots.reserve(size);
}

void Tube::push(uint8_t dot)
{
	this->dots.push_back(dot);
}

void Tube::pop()
{
	this->dots.pop_back();
}

bool Tube::isEmpty() const
{
	return this->dots.empty();
}

bool Tube::isFull() const
{
	return (this->dots.size() == this->size);
}

bool Tube::isCompleted() const
{
	if(!this->isFull())
	{
		return false;
	}

	for(uint8_t i = 1; i < this->dots.size(); ++i)
	{
		if(this->dots[i] != this->dots[0])
		{
			return false;
		}
	}
	return true;
}

uint8_t Tube::top() const
{
	return this->dots.back();
}

bool Tube::isSuitableDot(uint8_t dot) const
{
	if(this->isEmpty())
	{
		return true;
	}
	return (this->top() == dot);
}

const std::vector<uint8_t>& Tube::getDots() const
{
	return this->dots;
}
